//
//  BaseRequest.h
//  iPhoneKML
//
//  Created by Benjamin Blundell on 16/10/2009.
//  Copyright 2009 Centre for Advanced Spatial Analysis. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BaseRequestDelegate.h"

// A Wrapper class around the NSURL and similar objects for
// accessing REST services
// This class does not deal with JSON. Rather it is generic
// for all kinds of requests, JSON or otherwise.

@interface BaseRequest : NSObject {
	
	int					timeout;
	
@protected
	id<BaseRequestDelegate> delegate;
	NSMutableString				*baseURLString;
	NSMutableString				*commandVars;
	NSMutableURLRequest			*request;
	NSURLResponse				*response;
	
	NSURLConnection				*urlConnection;
	NSMutableData				*data;
	NSMutableDictionary			*postVars;
	NSMutableDictionary			*headerVars;
	
}

@property (nonatomic, assign) id<BaseRequestDelegate> delegate;
@property (nonatomic, assign) NSMutableString *baseURLString;

// The last request made.
@property (nonatomic, readonly) NSMutableURLRequest *request;

// The last response eceived.
@property (nonatomic, readonly) NSURLResponse *response;

// Returns an immutable copy of the last data eceived.
@property (nonatomic, readonly) NSData *data;

// Returns an immutable string copy of the last data eceived.
@property (nonatomic, readonly) NSString *stringData;

// Post variables
@property (nonatomic, assign) NSMutableDictionary	*postVars;

// command variables
@property (nonatomic, assign) NSMutableString	*commandVars;

// command variables
@property (nonatomic, assign) NSMutableDictionary	*headerVars;

// Designated Initializer
- (id)initWithBaseURL:(NSString *)baseURL;
- (void)performRequest;

@end
